
function setupWebViewJavascriptBridge(callback) {
    if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
    if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
    window.WVJBCallbacks = [callback];
    var WVJBIframe = document.createElement('iframe');
    WVJBIframe.style.display = 'none';
    WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
    document.documentElement.appendChild(WVJBIframe);
    setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}

var u = navigator.userAgent;
if (u.indexOf('iPhone') > -1) {   //苹果手机
    setupWebViewJavascriptBridge(function(bridge) {
        bridge.registerHandler('testJSFunction', function(data, responseCallback) {
            //alert('JS方法被调用:'+data);
            responseCallback('js执行过了');
        })
    });
}

/* IOS方法 */
function gotoNativeIos(nativeSchema,nativeParameter) {
    var params = {'nativeSchema':nativeSchema,'nativeParameter':nativeParameter};
    WebViewJavascriptBridge.callHandler('gotoNative',params,function(response) {
        //alert('gotoNative方法返回值:' + response);
        ayer.open({
            content: 'gotoNative方法返回值:'+response
            ,btn: '确定'
        });
        return response
    });
}
/* 安卓手机 */
function gotoNative(nativeSchema,nativeParameter) {
    var params = {'nativeSchema':nativeSchema,'nativeParameter':nativeParameter};
    var str=jsObj.gotoNative(JSON.stringify(params));
    //alert('gotoNative方法返回值:'+str)
    ayer.open({
        content: 'gotoNative方法返回值:'+str
        ,btn: '确定'
    });
    return str
}

function native(nativeParameter) {
    var u = navigator.userAgent;
    if (u.indexOf('iPhone') > -1) {   //苹果手机
        setTimeout(function () {
            gotoNativeIos('',nativeParameter);
        },50)
        setTimeout(function () {

        },100)
    }else{
        gotoNative('',nativeParameter);
    }
}


var vm=null;

function getData() {
    //alert('token='+localStorage.token+' nickCode='+localStorage.nickCode)
    var url='/equipment/newVersion/stopSetail';
    var mdObj=md5Fun(appUserId,url,appToken);
    $.ajax({
        type: "POST",
        timeout : 5000,
        url: webUrlCon+url,
        data: {id:localStorage.id},
        beforeSend: function(request) {
            //request.setRequestHeader("Content-Type", "application/json");
            request.setRequestHeader("sequence", mdObj.sequence);
            request.setRequestHeader("nonceStr", mdObj.nonceStr);
            request.setRequestHeader("userId", appUserId);
            request.setRequestHeader("token",appToken);
            //xmlhttp.setRequestHeader("infName", url);
            //xmlhttp.setRequestHeader("osVersion", '');
            request.setRequestHeader("versionType", "0");
            request.setRequestHeader("osPlatform", mdObj.osPlatform);
            request.setRequestHeader("appVersion", mdObj.appVersion);
            request.setRequestHeader("sign", mdObj.sign);
        },
        success: function (data) {
            console.log(data)
            if(data.code==100){
                 vm=new Vue({
                    el: '#main',
                    data: {
                        no:localStorage.no,
                        departmentName:localStorage.departmentName,
                        modelName:localStorage.modelName,
                        brandName:localStorage.brandName,
                        systemBrand:localStorage.systemBrand,
                        nickcode:localStorage.nickcode,
                        equipmentRecord: data.content
                    },
                    methods: {
                        downtimeType:function (type) {
                            if(type=='保养停机'){
                                return 'maintenance';
                            }
                            else if(type=='待单停机') {
                                return 'staySingle';
                            }
                            else if(type=='待料停机') {
                                return 'reliable';
                            }
                            else if(type=='工艺停机') {
                                return 'process';
                            }
                            else if(type=='故障停机') {
                                return 'malfunction';
                            }
                            else if(type=='假期停机') {
                                return 'vacation';
                            }
                            else if(type=='维修停机') {
                                return 'service';
                            }
                            else if(type=='争议停机') {
                                return 'controversy';
                            }
                            else if(type=='自定义停机') {
                                return 'custom';
                            }
                            else if(type=='常规停机') {
                                return 'conventional';
                            }
                            else{
                                return '';
                            }
                        },
                        downtimeStatus:function (type) {
                            if(type=='1'){
                                return '维修工单已生成';
                            }
                            else if(type=='2') {
                                return '已派工单至内部';
                            }
                            else if(type=='3') {
                                return '已派工单至外部';
                            }
                            else if(type=='4') {
                                return '已忽略此维修工单';
                            }
                            else if(type=='6') {
                                return '维修中(未申请配件)';
                            }
                            else if(type=='7') {
                                return '维修中(已申请配件)';
                            }
                            else if(type=='8') {
                                return '维修主管已通过配件申请';
                            }
                            else if(type=='9') {
                                return '维修主管已驳回配件申请';
                            }
                            else if(type=='10') {
                                return '采购部/仓储部处理配件申请中';
                            }
                            else if(type=='11') {
                                return '已提交修复记录';
                            }
                            else if(type=='12') {
                                return '采购部/仓储部配件申请已完成';
                            }else if(type=='15') {
                                return '维修主管已撤回工单';
                            }else if(type=='0') {
                                return '无法跟踪流程进度';
                            }
                            else{
                                return '';
                            }
                        },
                        statusShow:function (status) {
                            if(status >= 6&&status <=12&&status!=15){
                                return true
                            }else{
                                return false
                            }
                        },
                        nativeClick:function (itme) {
                            var params={
                                nickcode:this.nickcode,
                                departmentName:this.departmentName,
                                modelName:this.modelName,
                                brandName:this.brandName,
                                systemBrand:this.systemBrand,
                                no:this.no,
                               /* stopDetailList:[{
                                        /!*repair_id:parseInt(localStorage.id),
                                        status:itme.status,
                                        timeDiff:itme.timeDiff,
                                        changBy:itme.changBy,
                                        remark:itme.remark,
                                        level:itme.level,
                                        notify:itme.notify*!/
                                    }],*/
                                stopDetailList:[itme]

                            }
                            native(JSON.stringify(params));
                        },
                        timeDiff:function (time) {
                            time=time.replace(/:/,"h");
                            time=time.replace(/:/,"m");
                            var timeLen=time.indexOf("m");
                            time=time.substring(0,timeLen+1);
                            return time
                        },
                    }

                })
                document.getElementById("spinner").style.display="none";
                document.getElementById("main").style.display="block";
            } else if(data.code==-2){
                layer.open({
                    content: data.code+' 数据故障'
                    ,btn: '确定'
                });
            }else{
                //fundebug.notify("equipment/searchRecord接口返回数据", JSON.stringify(data));
                layer.open({
                    content: data.code+data.message
                    ,btn: '确定'
                });
            }
        },
        error: function(e) {
            layer.open({
                content: '无法请求服务器，请稍后再试！'
                ,btn: '确定'
            });
        }
    });
}

$(document).ready(function(){
    getData();
});